package cn.itsource.pethome.web.controller;

import cn.itsource.pethome.domain.Shop;
import cn.itsource.pethome.query.ShopQuery;
import cn.itsource.pethome.service.IShopService;
import cn.itsource.pethome.utils.AjaxResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ShopController {

    @Autowired
    private IShopService shopService;

    @PatchMapping("/shop")
    public PageInfo<Shop> page(@RequestBody ShopQuery shopQuery){
        return shopService.findPage(shopQuery);
    }

    /**
     * 商家入驻审核：平台内部员工使用
     * @param id
     * @param auditState
     * @return
     */
    @GetMapping("/shop/audit/{id}/{auditState}")
    public AjaxResult audit(@PathVariable("id")Long id, @PathVariable("auditState")Integer auditState){
        try {
            shopService.audit(id, auditState);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("审核失败！" + e.getMessage());
        }
    }

}
